<?php

declare(strict_types=1);

use Hyperf\HttpServer\Router\Router;

// 定义常用的中间件组合
$encryptedApiMiddlewares = [
    // 中间件的执行顺序很重要：先解密，再验证，最后加密响应
    \App\Middleware\DecryptMiddleware::class,
    \Hyperf\Validation\Middleware\ValidationMiddleware::class,
    \App\Middleware\EncryptResponseMiddleware::class,
];

// 不需要解密但需要验证的API
$validationMiddlewares = [
    \Hyperf\Validation\Middleware\ValidationMiddleware::class,
];

// 普通路由，不需要加解密和验证
Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController@index');
Router::post('/test/decrypt', [\App\Controller\TestController::class, 'decrypt'], ['middleware' => [\App\Middleware\DecryptMiddleware::class]]);
Router::post('/test/encrypt', [\App\Controller\TestController::class, 'encrypt'], ['middleware' => [\App\Middleware\EncryptResponseMiddleware::class]]);

// 点击监测链接
Router::addGroup('/clickMonitor/', function () {
    Router::get('oppo/click', [\App\Controller\ClickMonitor\OppoController::class, 'click']);
    Router::post('vivo/click', [\App\Controller\ClickMonitor\VivoController::class, 'click']);
});

Router::addGroup('/launch/', function () {
    Router::get("encryptExample", [\App\Controller\LaunchController::class, "encryptExample"]);
});

Router::addGroup('/launch/', function () {
    Router::post("initInfo", [\App\Controller\LaunchController::class, "initInfo"]);
    Router::post("secondInitInfo", [\App\Controller\LaunchController::class, "secondInitInfo"]);
}, ['middleware' => $encryptedApiMiddlewares]);

Router::addGroup('/report/', function () {
    Router::post('launch', [\App\Controller\ReportController::class, 'launch']);
    Router::post('cpm', [\App\Controller\ReportController::class, 'cpm']);
    Router::post('adRequest', [\App\Controller\ReportController::class, 'adRequest']);
    Router::post('behavior', [\App\Controller\ReportController::class, 'behavior']);
}, ['middleware' => $encryptedApiMiddlewares]);
